<?php

namespace App\Http\Controllers\admin;

use App\Models\Deposit;
use App\Models\Order;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{
    public function __construct()
    {

        view()->share([
            '_index' => 'am-active',
        ]);
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $total_sale=Order::where('is_pay',1)->where('type','!=','5')->sum('price');
        $total_deposit=Deposit::where('is_pay',1)->sum('deposit_number');
        $td=Carbon::now();
        $knownDate = Carbon::create($td->year, $td->month, 1, 0);
        $yue=Order::whereBetween('created_at', [$knownDate, Carbon::now()])->where('is_pay',1)->sum('price');
        $day=Order::whereBetween('created_at', [Carbon::today(), Carbon::now()])->where('is_pay',1)->sum('price');
        return view('admin.index',compact('total_sale','total_deposit','yue','day'));
    }
}
